package com.pt25.service.sys.domain.admin.factory;

import com.pt25.base.util.JsonUtil;
import com.pt25.service.sys.domain.admin.ddo.AdminPermission;
import com.pt25.service.sys.domain.admin.ddo.AdminRole;
import com.pt25.service.sys.domain.admin.ddo.AdminUser;
import com.pt25.service.sys.repository.mysql.po.AdminPermissionPo;
import com.pt25.service.sys.repository.mysql.po.AdminRolePo;
import com.pt25.service.sys.repository.mysql.po.AdminUserPo;
import org.springframework.stereotype.Component;

@Component
public class AdminFactory {
    public AdminUserPo adminUser2AdminUserPO(AdminUser adminUser) {
        return JsonUtil.toBean(JsonUtil.toJson(adminUser), AdminUserPo.class);
    }


    public AdminRolePo adminRole2AdminRolePO(AdminRole adminRole) {
        return JsonUtil.toBean(JsonUtil.toJson(adminRole), AdminRolePo.class);
    }


    public AdminPermissionPo adminPermission2AdminPermissionPO(AdminPermission adminPermission) {
        AdminPermissionPo adminPermissionPO = AdminPermissionPo.builder()
                .permission(adminPermission.getPermission())
                .title(adminPermission.getTitle())
                .build();
        adminPermissionPO.setSort(adminPermission.getSort());
        adminPermissionPO.setId(adminPermission.getId());
        adminPermissionPO.setParentId(adminPermission.getParentId());
        return adminPermissionPO;
    }

    public <T> T adminPermission2AdminPermissionVO(AdminPermission adminPermission, Class<T> clazz) {
        return JsonUtil.toBean(adminPermission, clazz);
    }

}
